﻿namespace Ex03.GarageLogic
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    public enum eFuelType
    {
        Soler = 1,
        Octan98,
        Octan96,
        Octan95
    }

    internal class FuelEngine : Engine
    {
        #region Messages
        private const string k_FuelType = "Fuel type: ";
        private const string k_Liters = "{0} Liters";
        private const string k_FuelTypeNotDefined = @"Fuel type doesn't exists in system.";
        private const string k_FuelExceedsMax =
@"Fuel quantity exceeds the maximum allowed.
{0} Liters left to fill.";
        #endregion

        #region Data Members
        private readonly eFuelType r_FuelType;
        private readonly float r_MaximumFuelCapacity;
        private float m_CurrentFuelQuantity;
        #endregion

        #region Constructors
        public FuelEngine(eFuelType i_FuelType, float i_MaximumFuelCapacity)
            : base()
        {
            r_FuelType = i_FuelType;
            r_MaximumFuelCapacity = i_MaximumFuelCapacity;
        }
        #endregion

        #region Properties
        public eFuelType FuelType
        {
            get { return r_FuelType; }
        }
        #endregion

        #region Public Methods
        public void AddFuelSource(eFuelType i_FuelType, float i_QuantityOfFuel)
        {
            float littersToAdd = m_CurrentFuelQuantity + i_QuantityOfFuel;

            if (Enum.IsDefined(typeof(eFuelType), i_FuelType))
            {
                if (littersToAdd <= r_MaximumFuelCapacity)
                {
                    m_CurrentFuelQuantity = littersToAdd;
                }
                else
                {
                    throw new ValueOutOfRangeException(string.Format(k_FuelExceedsMax, ((float)(r_MaximumFuelCapacity - m_CurrentFuelQuantity)).ToString()), 0, r_MaximumFuelCapacity);
                }
            }
            else
            {
                throw new ArgumentException(k_FuelTypeNotDefined);
            }
        }

        public override void UpdateCurrentCapacityByPercentage(float i_Percentage)
        {
            m_CurrentFuelQuantity = (r_MaximumFuelCapacity * i_Percentage) / 100;
        }

        public override float CalculatePercentageByCurrentEnergy()
        {
            return (m_CurrentFuelQuantity / r_MaximumFuelCapacity) * 100;
        }

        public override void GetAllDetails(ref List<string> io_ListOfVehicleDetails)
        {
            io_ListOfVehicleDetails.Add(GarageLogic.s_EmptyLine);
            io_ListOfVehicleDetails.Add(k_DisplayEngine);
            io_ListOfVehicleDetails.Add(string.Format(GarageLogic.s_PrintParameter, k_EngineType, Enum.GetName(typeof(eEngineType), 1)));
            io_ListOfVehicleDetails.Add(string.Format(GarageLogic.s_PrintParameter, k_FuelType, r_FuelType.ToString()));
            io_ListOfVehicleDetails.Add(string.Format(GarageLogic.s_PrintParameter, k_CurrentEnergyCapacity, string.Format(k_Liters, m_CurrentFuelQuantity.ToString())));
            io_ListOfVehicleDetails.Add(string.Format(GarageLogic.s_PrintParameter, k_MaximumEnergyCapacity, string.Format(k_Liters, r_MaximumFuelCapacity.ToString())));
        }
        #endregion
    }
}
